package com.focusmes.modules.base.workshop.component;

import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.online.cgform.enhance.CgformEnhanceJavaInter;
import org.jeecg.modules.online.cgform.mapper.OnlCgformFieldMapper;
import org.jeecg.modules.online.config.exception.BusinessException;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 编辑车间
 */
@Component("enWorkshopEdit")
public class EnWorkshopEdit implements CgformEnhanceJavaInter {
    @Override
    public int execute(String tableName, JSONObject json) throws BusinessException {
//        System.out.println("===============================");
//        System.out.println(tableName);
//        System.out.println(json.getString("factory_id"));
//        System.out.println(json.toJSONString());

        OnlCgformFieldMapper onlCgformFieldMapper = SpringContextUtils.getBean(OnlCgformFieldMapper.class);
        Map<String,Object> params = new HashMap<>();
        String sql = "update "+ tableName+" set factory_id=#{factory_id,jdbcType=VARCHAR} where id=#{id,jdbcType=VARCHAR}";
        params.put("execute_sql_string",sql);
        params.put("factory_id",json.getString("factory_id"));
        params.put("id",json.getString("id"));
        onlCgformFieldMapper.executeUpdatetSQL(params);
        return 1;
    }
    @Override
    public int execute(String tableName, Map<String, Object> data) throws BusinessException {
        return 1;
    }
}